/**
 * NoteDao.java
 * com.ebook.server.dao
 * Copyright (c) 2013, 公司版权所有.
*/

package com.ebook.server.dao;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.ebook.core.domain.Bookmarker;

/**
 * 
 * @author    潘吉友
 * @Date	 2013-7-25 	 
 */
@Repository
public class BookMarkerDao {
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	private static Log logger = LogFactory.getLog(BookMarkerDao.class);
	
	public void add(Bookmarker b){
		String insertSql = "insert into bookmarker (markerid,uid,bookid,cfi,curr_chapter,title,content,create_time) values(?,?,?,?,?,?,?,?)";
		logger.info("|add|"+insertSql);
		try{
			jdbcTemplate.update(insertSql, b.getMarkerid().toString(), b.getUid(), b.getBookid(), b.getCfi(),
					b.getCurr_chapter(), b.getTitle(), b.getContent(), b.getCreate_time().toString());
		}catch(Exception e){
			logger.error("|add|insert into bookmarker error!");
			throw new RuntimeException(e);
		}
	}
	
	public boolean isExistsByid(String id){
		String selectSql = "select count(*) from bookmarker where markerid=? ";
		logger.info("|isExistsByid|"+selectSql);
		return jdbcTemplate.queryForInt(selectSql,id)> 0 ? true : false;
	}

	public void delete(String markerid) {
		String deleteSql = "delete from bookmarker where markerid=? ";
		logger.info("|delete|"+deleteSql);
		jdbcTemplate.update(deleteSql, markerid);
	}
	
	
}

